<?php

namespace app\controller\common;

use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use Darabonba\OpenApi\Models\Config;

class Sms
{
    public static function sendCaptcha($phoneNumbers,$code,$signName,$templateCode,$conf){
        $config = new Config(config('sms.'.$conf));
        $client = new Dysmsapi($config);
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $phoneNumbers,
            "signName" => $signName,
            "templateCode" => $templateCode,
            "templateParam" => json_encode(array("code"=>$code),JSON_UNESCAPED_SLASHES)
        ]);
        $res = $client->sendSms($sendSmsRequest);
        return $res->toMap()['body'];
    }

    public static function send($mobiles,$tmpCode,$signName,$conf){
        $config = new Config(config('sms.'.$conf));
        $client = new Dysmsapi($config);
        $sendSmsRequest = new SendSmsRequest([
            "phoneNumbers" => $mobiles,
            "signName" => $signName,
            "templateCode" => $tmpCode
        ]);
        $res = $client->sendSms($sendSmsRequest);
        return $res->toMap()['body'];
    }
}